package main

import (
	"crypto/hmac"
	"crypto/sha1"
	"fmt"
	"strings"
	"time"
)

func getFmtDate(ts int64, format string) string {
	t := time.Unix(ts, 0)
	patterns := []string{
		"Y", "2006",
		"y", "06",
		"m", "01",
		"n", "1",
		"M", "Jan",
		"F", "January",
		"d", "02",
		"j", "2",
		"D", "Mon",
		"l", "Monday",
		"g", "3",
		"G", "15",
		"h", "03",
		"H", "15",
		"a", "pm",
		"A", "PM",
		"i", "04",
		"s", "05",
	}
	replacer := strings.NewReplacer(patterns...)
	format = replacer.Replace(format)
	return t.Format(format)
}

func getHash(str, sec string) string {
	hm := hmac.New(sha1.New, []byte(sec))
	hm.Write([]byte(str))
	return fmt.Sprintf("%02x", hm.Sum(nil))
}
